package userInterface;

import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
import javax.swing.JTextArea;
import javax.swing.JButton;

import cliente.GerenciaCliente;

import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class CadastroClienteGUI {
	
	//	Atributos de cliente(gerenciador)
	private GerenciaCliente gerenciador;
	

	private JFrame frame;
	private JTextField textNome;
	private JTextField textTel;
	private JTextField textEndere;
	private JTextField textCelular;
	private JTextField textField;
	private JTextField renda;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					CadastroClienteGUI window = new CadastroClienteGUI();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public CadastroClienteGUI() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 467, 367);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		
		JPanel panel = new JPanel();
		panel.setBorder(new TitledBorder(null, "Dados do Cliente", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel.setBounds(10, 11, 430, 259);
		frame.getContentPane().add(panel);
		panel.setLayout(null);
		
		JLabel lblNome = new JLabel("Nome:");
		lblNome.setFont(new Font("Dialog", Font.PLAIN, 12));
		lblNome.setBounds(10, 26, 37, 16);
		panel.add(lblNome);
		
		textNome = new JTextField();
		textNome.setBounds(62, 26, 358, 20);
		panel.add(textNome);
		textNome.setColumns(10);
		
		JLabel lblEndereo = new JLabel("Endere\u00E7o:");
		lblEndereo.setFont(new Font("Dialog", Font.PLAIN, 12));
		lblEndereo.setBounds(10, 51, 56, 16);
		panel.add(lblEndereo);
		
		textEndere = new JTextField();
		textEndere.setBounds(69, 51, 351, 20);
		panel.add(textEndere);
		textEndere.setColumns(10);
		
		JLabel lblTelefone = new JLabel("Telefone:");
		lblTelefone.setFont(new Font("Dialog", Font.PLAIN, 12));
		lblTelefone.setBounds(10, 82, 51, 16);
		panel.add(lblTelefone);
		
		JLabel lblRenda = new JLabel("Renda:");
		lblRenda.setFont(new Font("Dialog", Font.PLAIN, 12));
		lblRenda.setBounds(10, 107, 40, 16);
		panel.add(lblRenda);
		
		JLabel lblInteresses = new JLabel("Interesses:");
		lblInteresses.setFont(new Font("Dialog", Font.PLAIN, 12));
		lblInteresses.setBounds(10, 157, 62, 16);
		panel.add(lblInteresses);
		
		JLabel lblPerfilMdico = new JLabel("Perfil M\u00E9dico:");
		lblPerfilMdico.setFont(new Font("Dialog", Font.PLAIN, 12));
		lblPerfilMdico.setBounds(10, 132, 73, 16);
		panel.add(lblPerfilMdico);
		
		textTel = new JTextField();
		textTel.setBounds(69, 82, 134, 20);
		panel.add(textTel);
		textTel.setColumns(10);
		
		JLabel lblCelular = new JLabel("Celular:");
		lblCelular.setFont(new Font("Dialog", Font.PLAIN, 12));
		lblCelular.setBounds(217, 85, 43, 16);
		panel.add(lblCelular);
		
		textCelular = new JTextField();
		textCelular.setBounds(264, 82, 156, 20);
		panel.add(textCelular);
		textCelular.setColumns(10);
		
		JLabel lblSalriosMnimos = new JLabel("Sal\u00E1rios M\u00EDnimos");
		lblSalriosMnimos.setFont(new Font("Dialog", Font.PLAIN, 12));
		lblSalriosMnimos.setBounds(147, 107, 96, 16);
		panel.add(lblSalriosMnimos);
		
		textField = new JTextField();
		textField.setBounds(93, 132, 327, 20);
		panel.add(textField);
		textField.setColumns(10);
		
		JTextArea textArea = new JTextArea();
		textArea.setBounds(10, 184, 410, 64);
		panel.add(textArea);
		
		renda = new JTextField();
		renda.setBounds(62, 106, 75, 20);
		panel.add(renda);
		renda.setColumns(10);
		
		
		
		JButton btnAdicionar = new JButton("Adicionar");
		//	Cadastra cliente
		//		cria gerenciador de clientes
		gerenciador = GerenciaCliente.getInstance(); 
		//		evento que add clientes na hashlist de gerenciador
		btnAdicionar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if (gerenciador.cadastraCliente(textNome.getText(),textEndere.getText() , textTel.getText(),Double.parseDouble( renda.getText() ) ) )
				{
					JOptionPane.showMessageDialog(null,"Ciente adicionado com successo","Cliente adicionado", JOptionPane.INFORMATION_MESSAGE);  			
				}

				
			}
		});
		
		btnAdicionar.setBounds(169, 281, 91, 37);
		frame.getContentPane().add(btnAdicionar);

		
		
		JButton btnCancelar = new JButton("Cancelar");
		btnCancelar.setBounds(351, 289, 89, 23);
		frame.getContentPane().add(btnCancelar);
	}
}
